package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Role;
import com.qianfeng.entity.Subject;
import com.qianfeng.mapper.SubjectMapper;
import com.qianfeng.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class SubjectServiceImpl implements SubjectService {

    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public void addSubject(Subject subject) {
        subjectMapper.addSubject(subject);
    }

    @Override
    public void deleteSubject(Integer subjectId) {
        subjectMapper.deleteSubject(subjectId);
    }

    @Override
    public void updateSubject(Subject subject) {
        subjectMapper.updateSubject(subject);
    }

    @Override
    public List<Subject> getListBySubjectId(Integer subjectId) {
        List<Subject> list = subjectMapper.getListBySubjectId(subjectId);
        return list;
    }

    @Override
    public List<Subject> getSubjectList() {
        List<Subject> subjectList = subjectMapper.getSubjectList();
        return subjectList;
    }


    @Override
    public Page getSubjectPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Subject> subjectList = subjectMapper.getSubjectList();
        Page page = new Page();
        PageInfo<Subject> pageInfo = new PageInfo<>(subjectList);
        page.setCount(pageInfo.getTotal());
        page.setObj(pageInfo.getList());
        page.setPages(pageInfo.getPages());
        return page;
    }
}
